package info.liuxing.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * LogAspects
 * <p>
 * // @Aspect 声明当前类是一个切面类
 *
 * @author liuxing
 * @summary LogAspects
 * @Copyright (c) 2018, Lianjia Group All Rights Reserved.
 * @since 2018-05-01 19:29
 */
@Slf4j
@Aspect
public class LogAspects {

    /**
     * 抽取公共的切入点表达式
     * 1、本类引用
     * 2、其他切面引用
     */
    @Pointcut("execution(public int info.liuxing.aop.MathCalculator.division(int, int))")
//    @Pointcut("execution(public int info.liuxing.aop.MathCalculator.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint) {
        log.debug("{}运行，参数列表是：{}", joinPoint.getSignature().getName(), joinPoint.getArgs());
    }

    @After("info.liuxing.aop.LogAspects.pointCut()")
    public void logEnd(JoinPoint joinPoint) {
        log.debug("{}结束", joinPoint.getSignature().getName());
    }

    @AfterReturning(value = "pointCut()", returning = "result")
    public void logReturn(JoinPoint joinPoint, Object result) {
        log.debug("{}正常返回，运行结果：{}", joinPoint.getSignature().getName(), result);
    }

    @AfterThrowing(value = "pointCut()", throwing = "e")
    public void logException(JoinPoint joinPoint, Exception e) {
        log.debug("{}异常，异常信息：{}", joinPoint.getSignature().getName(), e.getMessage());
    }

}
